package com.edittable.dwr;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.edittable.bean.EmpInfo;
import com.edittable.dao.EmpInfoDao;
import com.edittable.dao.IEmpInfoDao;

public class EmpInfoDwr {
	private IEmpInfoDao empInfoDao=new EmpInfoDao();
    public List<EmpInfo> selectAll(){
    	return empInfoDao.selectAll();
    }
    public List<EmpInfo> selectByEname(String ename){
    	return empInfoDao.selectByName(ename);
    }
    public void deleteByEmpno(int empno){
    	empInfoDao.deleteByEmpno(empno);
    }
    @SuppressWarnings("deprecation")
	public void saveOrupdate(String[] oldData,String[] newData){
    	List<EmpInfo> updateList=new ArrayList<EmpInfo>();
    	List<EmpInfo> savedateList=new ArrayList<EmpInfo>();
    	EmpInfo emp=null;
    	int k=0;
    	System.out.println("修改");
    	for(int i=0;i<oldData.length;i++){
    		emp=new EmpInfo();
    		emp.setEmpno(Integer.parseInt(newData[k+0]));
    		emp.setEname(newData[k+1]);
    		emp.setJob(newData[k+2]);
    		emp.setMgr(Integer.parseInt(newData[k+3]));
    		emp.setHiredate(new Date(newData[k+4]));
    		emp.setSal(Float.parseFloat(newData[k+5]));
    		emp.setComm(Float.parseFloat(newData[k+6]));
    		emp.setDeptno(Integer.parseInt(newData[k+7]));
    		System.out.println(emp);
    		updateList.add(emp);
    		k=k+8;
    	}
    	empInfoDao.updateList(updateList);
    	System.out.println("保存");
    	int n=oldData.length*8;
    	for(int i=0;i<newData.length/8-oldData.length;i++){
    		System.out.println("n:"+n);
    		emp=new EmpInfo();
    		emp.setEmpno(Integer.parseInt(newData[n+0]));
    		emp.setEname(newData[n+1]);
    		emp.setJob(newData[n+2]);
    		emp.setMgr(Integer.parseInt(newData[n+3]));
    		emp.setHiredate(new Date(newData[n+4]));
    		emp.setSal(Float.parseFloat(newData[n+5]));
    		emp.setComm(Float.parseFloat(newData[n+6]));
    		emp.setDeptno(Integer.parseInt(newData[n+7]));
    		System.out.println(emp);
    		savedateList.add(emp);
    		n=n+8;
    	}
    	empInfoDao.insertList(savedateList);
    }
}
